package com.example.test.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.test.dao.UserAuthDao;
import com.example.test.domain.R;
import com.example.test.domain.UserAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    private UserAuthDao userAuthDao;

    @GetMapping("")
    public List<UserAuth> hello(){

        return userAuthDao.selectList(null);
    }

    @PostMapping("/create")
    public R create(@RequestBody UserAuth userAuth){
        LambdaQueryWrapper<UserAuth> lqw = new LambdaQueryWrapper<>();
        lqw.eq(UserAuth::getUsername, userAuth.getUsername());
        if (!userAuthDao.exists(lqw)){
            return new R(userAuthDao.insert(userAuth) > 0);
        }else {
            return new R();
        }

    }
}
